﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DBUtility;

namespace DAL
{
   public class AuthorityDAL
    {
        //通过id判断用户角色
      public string GetGroupIDByid(string ID)
      {
          DataSet ds = new DataSet();
          StringBuilder sql = new StringBuilder();
          string group_id = string.Empty;
          sql.Append("select  m.group_id from master t,mastergroup m where m.master_id=t.id  and  t.id='"+ID+"'" );

          try
          {
              ds = DbHelperOra.Query(sql.ToString());
              if (ds != null && ds.Tables[0].Rows.Count > 0)
              {
                  foreach (DataRow dr in ds.Tables[0].Rows)
                  {
                      group_id = dr["group_id"].ToString();
                  }
              }
          }
          catch (Exception ex)
          {
              throw ex;
          }
          return group_id;
      }

       //通过ID判断用户权限
      public string GetPDAAuthority(string ID)
      {
          string  result = "";
          StringBuilder sql = new StringBuilder();
          string groupid = GetGroupIDByid(ID);
          DataSet ds = new DataSet();
          if (groupid != null && groupid != "")
          {
              sql.Append("  select * from action t,actiongroup g where t.action(+)=g.action and t.action_columnid='19' and group_id='" + groupid + "'");
           

              try
              {
                  ds = DbHelperOra.Query(sql.ToString());
                  if (ds != null && ds.Tables[0].Rows.Count > 0)
                  {
                      for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                      {
                          result = result + ds.Tables[0].Rows[i]["action"].ToString() + ',';
                      }                    
                  }
              }
              catch (Exception ex)
              {
                  throw ex;
              }
          }
          return result;
      }


      //public string AnalysisF(string code)
      //{ 
      
      //}
    }
}
